package com.ckx.controller;

import com.ckx.domain.ResponseResult;
import com.ckx.domain.dto.UserAddDto;
import com.ckx.domain.dto.UserStatusDto;
import com.ckx.domain.dto.UserUpdateDto;
import com.ckx.domain.entity.User;
import com.ckx.domain.vo.PageVo;
import com.ckx.domain.vo.UserInfoByAdminVo;
import com.ckx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/system/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, User user){
        PageVo pageVo = userService.listByPage(pageNum, pageSize, user);
        return ResponseResult.okResult(pageVo);
    }

    @PostMapping
    public ResponseResult addUser(@RequestBody UserAddDto userAddDto){
        userService.addUser4Admin(userAddDto);
        return ResponseResult.okResult();
    }

    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody UserStatusDto userStatusDto){
        userService.changeStatus(userStatusDto);
        return ResponseResult.okResult();
    }

    @GetMapping("/{id}")
    public ResponseResult getUserInfo(@PathVariable Long id){
        UserInfoByAdminVo userInfoByAdminVo = userService.getUserInfo(id);
        return ResponseResult.okResult(userInfoByAdminVo);
    }

    @PutMapping
    public ResponseResult updateUser(@RequestBody UserUpdateDto userUpdateDto){
        userService.updateUser(userUpdateDto);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delUser(@PathVariable Long id){
        userService.del4DelFlag(id);
        return ResponseResult.okResult();
    }

}
